﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using LogisticsDAL;
using Model;

namespace LogisticsBLL
{
    public class CarriessCyBLL
    {
        /// <summary>
        /// 承运单管理信息
        /// </summary>
        /// <returns></returns>
        public DataTable readCarrierBind(int pageIndex, int pageSize, out int Count, Carriers cars)
        {
            CarresssCyDAL cdl = new CarresssCyDAL();
            DataTable read = cdl.sqlCarrierList(pageIndex,pageSize, out Count,cars);
            
            return read;
        }

        /// <summary>
        /// 承运单签收页面
        /// </summary>
        /// <returns></returns>
        public DataTable readCarrierRecepront(int pageIndex, int pageSize, out int Count, Carriers cars)
        {
            CarresssCyDAL cdl = new CarresssCyDAL();
            
            return cdl.sqlCarrierQian(pageIndex, pageSize, out Count, cars);
        }

        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="cars"></param>
        /// <returns></returns>
        public List<Carriers> SeletBindCarrier(Carriers cars)
        {
            CarresssCyDAL cardal = new CarresssCyDAL();
            return cardal.CarriesBind(cars);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="carriesID"></param>
        /// <returns></returns>
        public string DelCarrider(int carriesID)
        {
            CarresssCyDAL caydal = new CarresssCyDAL();
            string str = "";
            if (caydal.PDcarrID(carriesID) >=1 )
            {
                if (caydal.PDsching(carriesID) > 0)
                {
                    str = "调度任务信息表中存在该承运单信息，请先删除调度任务表中信息！";
                }
                else
                {
                 if (caydal.DelCarrier(carriesID) > 0)
                   {
                    str = "删除成功！";
                   }
                  else
                   {
                    str = "删除失败！";
                   }
                }
                
            }
            else
            {
                 str = "删除失败，数据库没有该承运单！";
            }
            return str;
        }


        /// <summary>
        /// 添加承运单
        /// </summary>
        /// <param name="cas"></param>
        /// <returns></returns>
        public string InsertCarries(Carriers cas)
        {
            CarresssCyDAL cyd = new CarresssCyDAL();
            string pages = "";

            if (cyd.InsetCarries(cas) > 0)
            {
                pages = "添加成功！";
            }
            else
            {
                pages = "添加失败！";
            }
            return pages;
        }
        public int PDrole(int carid)
        {
            CarresssCyDAL cyd = new CarresssCyDAL();
            int str = cyd.RoleName(carid);
            
            return str;
        }


        public Carriers Carrideail(int carrisID)
        {
            CarresssCyDAL cydal = new CarresssCyDAL();
            return cydal.CarriesDecial(carrisID);
        }

        public SqlDataReader Bindgoods(int carrisID)
        {
            CarresssCyDAL cyd = new CarresssCyDAL();
            return cyd.readCargo(carrisID);
        }


        public int GoodsInsert(Goods god)
        {
            CarresssCyDAL cyd = new CarresssCyDAL();
            return cyd.GoodsInsert(god);
        }


        /// <summary>
        /// 修改承运单
        /// </summary>
        /// <param name="cars"></param>
        /// <returns></returns>
        public int UpdateCaries(Carriers cars)
        {
            CarresssCyDAL cda = new CarresssCyDAL();
            return cda.UpdateCarres(cars);
        }


        /// <summary>
        /// 接收承运单页面条件查询
        /// </summary>
        /// <returns></returns>
        public List<Carriers> SelectCarriersDisplch(Carriers car)
        {
            CarresssCyDAL cyd = new CarresssCyDAL();
            return cyd.CarriesSelectDispaly(car);
        }


        /// <summary>
        /// 调度任务
        /// </summary>
        /// <param name="cars"></param>
        /// <returns></returns>
        public string CarriesSching(int carrid,int truckid,int userid)
        {

            CarresssCyDAL dy = new CarresssCyDAL();
            return dy.CarriesSching(carrid,truckid,userid);
        }



        public int SignCarries(int carriesid)
        {
            CarresssCyDAL cyd = new CarresssCyDAL();
            return cyd.SignCarries(carriesid);
        }
    }
}
